package com.example.java_second_hand_market;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class UserInfoDialog extends Stage {
    VBox vb;

    String DBUrl=ParameterDB.ParaDBUserUrl;
    String DBUser="root", DBPassword="123456";
    @FXML
    Label namel1=new Label("姓名");
    @FXML
    Label namel2 =new Label();
    @FXML
    Label accl1=new Label("账号");
    @FXML
    Label accl2 =new Label();
    @FXML
    Label banl1 = new Label("是否被封禁");
    @FXML
    Label banl2 = new Label();
    @FXML
    Button quit=new Button("退出");
    User us;
    public UserInfoDialog(User us,int width,int height){
        this.us=us;
        try {
            Connection con= DriverManager.getConnection(DBUrl,DBUser,DBPassword);
            Statement stmt=con.createStatement();
            ResultSet rs=stmt.executeQuery("SELECT * FROM user_list WHERE name = '"+us.getName()+"'");
            rs.next();
            namel2.setText(rs.getString("name"));
            accl2.setText(rs.getString("account"));
            banl2.setText(String.valueOf(rs.getInt("is_ban")));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        quit.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                close();
            }
        });
        vb=new VBox();

        HBox hb2=new HBox();
        hb2.getChildren().addAll(namel1,namel2);
        hb2.setMargin(namel1,new Insets(3,0,0,0));
        hb2.setMargin(namel2,new Insets(3,0,0,0));



        HBox hb1=new HBox();
        hb1.getChildren().addAll(accl1,accl2);
        hb1.setMargin(accl1,new Insets(3,0,0,0));
        hb1.setMargin(accl2,new Insets(3,0,0,0));

        HBox hb3=new HBox();
        hb3.getChildren().addAll(banl1,banl2);
        hb3.setMargin(banl1,new Insets(3,0,0,0));
        hb3.setMargin(banl2,new Insets(3,0,0,0));

        hb1.setAlignment(Pos.CENTER);
        hb2.setAlignment(Pos.CENTER);
        hb3.setAlignment(Pos.CENTER);


        vb.getChildren().addAll(hb2,hb1,hb3);
        vb.setAlignment(Pos.CENTER);

        BorderPane bp=new BorderPane();
        bp.setCenter(vb);
        bp.setBottom(quit);

        setX(820);
        setY(500);
        initModality(Modality.APPLICATION_MODAL);
        setScene(new Scene(bp));

        setWidth(700);
        setHeight(500);
        setX((width-getWidth()) / 2);
        setY((height-getHeight())/ 2);
        setTitle("个人信息");

    }
    public VBox getVBox(){
        return vb;
    }
}

